﻿<%@ Page Language="C#" EnableViewState="false" AutoEventWireup="true" CodeBehind="AddData.aspx.cs"
    Inherits="Forum.Web.Admin.Recommend.AddData" %>

<%@ Register Assembly="Public.Control" Namespace="Public.Control" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="../styles/control.css" type="text/css" rel="stylesheet" />
    <link href="../styles/dntmanager.css" rel="stylesheet" type="text/css" />
    <link href="../styles/modelpopup.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .ManagerForm.FormBase, .ManagerForm.FormFocus
        {
            line-height: 22px;
            height: 22px;
        }
        .hd
        {
            width: 40px;
            display:none;
        }
    </style>
</head>
<!--
<script src="../js/jquery/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
-->
<script src="../js/jquery/jquery.js" type="text/javascript"></script>
<script src="../js/jquery/ui/ui.core.js" type="text/javascript"></script>

<script src="../js/jquery/ui/ui.sortable.js" type="text/javascript"></script>
<script src="../js/modalpopup.js" type="text/javascript"></script>

<body class="ContentBody">
    <form id="form2" runat="server">
    <cc1:Hint ID="Hint1" runat="server" HintImageUrl="../" />
    <div class="ManagerForm">
        <fieldset>
            <legend style="background: url(../images/icons/icon25.jpg) no-repeat 6px 50%;">推荐数据</legend>
            <div class="MainDiv">
                <table id="tblRecommendClass" width="100%" border="0" cellpadding="0" cellspacing="0"
                    bgcolor="#EAE9E1">
                    <thead>
                        <tr bgcolor="#F2F2F2">
                            <td height="2" colspan="9" bgcolor="#CCCCCC">
                            </td>
                        </tr>
                        <tr bgcolor="#F2F2F2" style="font-weight: bold;">
                            <td class="title" width="80" height="35" align="center">
                                ID号
                            </td>
                            <td class="title" align="center">
                                标题
                            </td>
                            <td class="title" align="center" width="200">
                                描述
                            </td>
                            <td class="title" width="180" align="center">
                                图片地址
                            </td>
                            <td class="title" width="180" align="center">
                                链接地址
                            </td>
                            <td class="title" width="100" align="center">
                                颜色
                            </td>
                            <td class="title" width="60" align="center">
                                粗体
                            </td>
                            <td class="title" width="60" align="center">
                                保存
                            </td>
                            <td class="title" width="60" align="center">
                                删除
                            </td>
                        </tr>
                    </thead>
                    <tbody align="center" id="tj_list">
                        <asp:Repeater ID="Repeater1" runat="server">
                            <ItemTemplate>
                                <tr id='tr_<%#Eval("RdItems_ID") %>' bgcolor="#FFFFFF">
                                    <td height="35">
                                        <%#Eval("RdItems_ID") %><input d='hi' t='<%#Eval("RdItems_Type") %>' v='<%#Eval("RdItems_ID") %>'
                                            bodyid='<%#Eval("RdItems_BodyID") %>' class='hd' id="fld_sort_<%#Eval("RdItems_ID") %>"
                                            type="text" value="<%#Eval("RdItems_SortIndex") %>" />
                                            
                                        <textarea id='r_body_<%#Eval("RdItems_ID") %>'  cols='20' rows='2' style='display:none;'><%#Eval("RdItems_Body") %></textarea>
                                        <textarea id='r_spare_<%#Eval("RdItems_ID") %>'   cols='20' rows='2'  style='display:none;'><%#Eval("RdItems_Spare") %></textarea>
                                        <textarea id='r_spare2_<%#Eval("RdItems_ID") %>'    cols='20' rows='2'  style='display:none;'><%#Eval("RdItems_Spare2") %></textarea>

                                    </td>
                                    <td align='left'>
                                        <input type="text" value="<%#Eval("RdItems_Name") %>" id="fld_name_<%#Eval("RdItems_ID") %>"
                                            class="txt" onfocus="this.className='txt_focus';" onblur="this.className='txt';"
                                            style="width: 210px;" />
                                    </td>
                                    <td>
                                        <input type="text" value="<%#Eval("RdItems_Description") %>" id="fld_sm_<%#Eval("RdItems_ID") %>"
                                            class="txt" onfocus="this.className='txt_focus';" onblur="this.className='txt';"
                                            style="width: 210px;" />
                                    </td>
                                    <td>
                                        <input type="text" value="<%#Eval("RdItems_Tu") %>" id="fld_tu_<%#Eval("RdItems_ID") %>"
                                            class="txt" onfocus="this.className='txt_focus';" onblur="this.className='txt';"
                                            style="width: 150px;" />
                                    </td>
                                    <td>
                                        <input type="text" value="<%#Eval("RdItems_LinkURL") %>" id="fld_link_<%#Eval("RdItems_ID") %>"
                                            class="txt" onfocus="this.className='txt_focus';" onblur="this.className='txt';"
                                            style="width: 150px;" />
                                    </td>
                                    <td>
                                        <input type="text" value="<%#Eval("RdItems_Color") %>" id="fld_color_<%#Eval("RdItems_ID") %>"
                                            class="txt" onfocus="this.className='txt_focus';" onblur="this.className='txt';"
                                            style="width: 60px;" />
                                    </td>
                                    <td>
                                        <input id="fld_Bold_<%#Eval("RdItems_ID") %>" type="checkbox" <%#Eval("RdItems_Bold").ToString()=="1"?"checked":"" %> /><label
                                            for="fld_Bold_<%#Eval("RdItems_ID") %>">粗体</label>
                                    </td>
                                    <td>
                                        <button type="button" class="ManagerButton" id="Button5" onclick="updata(<%#Eval("RdItems_ID") %>)">
                                            <img src="../images/submit.gif" />保存</button>
                                    </td>
                                    <td>
                                        <button type="button" class="ManagerButton" id="Button1" onclick="deldata(<%#Eval("RdItems_ID") %>)">
                                            <img src="../images/state1.gif" />删除</button>
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                    </tbody>
                </table>
            </div>
        </fieldset>
        <div class="Navbutton">
            (已经推荐了 <span id="datacount" style="color:Red">0</span> 条数据) &nbsp;&nbsp;<cc1:Button ID="Button1" runat="server" ButtonImgUrl="../images/add.gif" Text="手动添加推荐内容"
                AutoPostBack="False" ScriptContent="BOX_show('neworedit')" />
        </div>
    </div>
    <div class="ManagerForm">
        <fieldset>
            <legend style="background: url(../images/icons/icon10.jpg) no-repeat 6px 50%;">文章列表</legend>
            <div class="MainDiv">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td height="300" align="right">
                            <iframe src="BodyList.aspx" frameborder="0" scrolling="no" width="100%" height="300">
                            </iframe>
                        </td>
                    </tr>
                </table>
        </fieldset>
    </div>
    <div id="neworedit" style="border-right: #999 1px solid; padding-right: 10px; border-top: #999 1px solid;
        display:none ; padding-left: 10px; background: #fff; padding-bottom: 10px; border-left: #999 1px solid;
        width: 600px; padding-top: 10px; border-bottom: #999 1px solid">
        <div class="ManagerForm">
            <fieldset>
                <legend style="background: url(../images/icons/icon4.jpg) no-repeat 6px 50%">手动添加推荐内容</legend>
                <div>
                    <table width="600" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td width="50" height="35">
                                名称:
                            </td>
                            <td>
                                <cc1:TextBox ID="f_name" runat="server" Width="295px"></cc1:TextBox>
                                (必填)
                            </td>
                        </tr>
                        <tr>
                            <td height="35">
                                描述:
                            </td>
                            <td>
                                <cc1:TextBox ID="TextBox1" runat="server" Width="450px" Height="60px" TextMode="MultiLine"></cc1:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td height="35">
                                内容:
                            </td>
                            <td style="padding-top:5px;">
                                <cc1:TextBox ID="TextBox3" runat="server" Width="450px" Height="60px" TextMode="MultiLine"></cc1:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td height="35">
                                图片:
                            </td>
                            <td>
                                <cc1:TextBox ID="f_linkurl" runat="server" Width="295px"></cc1:TextBox>(必填)
                            </td>
                        </tr>
                        <tr>
                            <td height="35">
                                链接:
                            </td>
                            <td>
                                <cc1:TextBox ID="f_shuoming" runat="server" Width="295px"></cc1:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td height="35">
                                颜色:
                            </td>
                            <td>
                                <cc1:TextBox ID="TextBox2" runat="server" Width="80px"></cc1:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td height="35">
                                加粗:
                            </td>
                            <td>
                                <input id="Checkbox1" type="checkbox" /><label for="Checkbox1">是/否</label>
                            </td>
                        </tr>
                        <tr>
                            <td height="35">
                                备用:
                            </td>
                            <td>
                                <cc1:TextBox ID="TextBox4" runat="server" Width="295px"></cc1:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td height="35">
                                备用2:
                            </td>
                            <td>
                                <cc1:TextBox ID="TextBox5" runat="server" Width="295px"></cc1:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;
                            </td>
                            <td>
                                <cc1:Button ID="Button3" runat="server" ButtonImgUrl="../images/add.gif" Text=" 提 交"
                                    AutoPostBack="False" ScriptContent="onsub__()" />
                                <cc1:Button ID="Button4" runat="server" ButtonImgUrl="../images/del.gif" Text=" 取 消"
                                    AutoPostBack="False" ScriptContent="BOX_remove('neworedit');" />
                            </td>
                        </tr>
                    </table>
                </div>
            </fieldset>
        </div>
    </div>

    <script type="text/javascript">
        var pid=<%=urlid %>;
        var id_=0;
        
        String.prototype.format = function() {
            if (arguments.length == 0)
                return null;
            var str = this;
            for (var i = 0; i < arguments.length; i++) {
                var re = new RegExp('\\{' + (i) + '\\}', 'gm');
                str = str.replace(re, arguments[i]);
            }
            return str;
        }

        var template = "<tr  id='tr_{0}' bgcolor='#FFFFFF'><td height='35'>"+
        "{0}<input d='hi' t='{1}'  v='{0}' bodyid='{2}' class='hd' id='fld_sort_{0}' type='text' value='{3}' />"+
    "</td><td align='left'>"+
        "<input  type='text' value='{4}' id='fld_name_{0}' class='FormBase' onFocus='this.className=\"FormFocus\";' onBlur='this.className=\"FormBase\";' style='width:210px; ' />"+
        "<textarea id='r_body_{0}'  cols='20' rows='2' style='display:none;'>{10}</textarea>"+
        "<textarea id='r_spare_{0}'   cols='20' rows='2'  style='display:none;'>{11}</textarea>"+
        "<textarea id='r_spare2_{0}'    cols='20' rows='2'  style='display:none;'>{12}</textarea>"+
    "</td><td>"+
        "<input  type='text' value='{5}' id='fld_sm_{0}' class='FormBase' onFocus='this.className=\"FormFocus\";' onBlur='this.className=\"FormBase\";' style='width:210px; ' />"+
    "</td><td>"+
        "<input type='text' value='{6}' id='fld_tu_{0}' class='FormBase' onFocus='this.className=\"FormFocus\";' onBlur='this.className=\"FormBase\";' style='width:150px; ' />"+
    "</td><td>"+
       "<input  type='text' value='{7}' id='fld_link_{0}' class='FormBase' onFocus='this.className=\"FormFocus\";' onBlur='this.className=\"FormBase\";' style='width:150px; ' />"+
    "</td><td>"+
       "<input  type='text' value='{8}' id='fld_color_{0}' class='FormBase' onFocus='this.className=\"FormFocus\";' onBlur='this.className=\"FormBase\";' style='width:60px; ' />"+
    "</td><td>"+
        "<input id='fld_Bold_{0}' type='checkbox' {9} /><label for='fld_Bold_{0}'>粗体</label>"+
    "</td><td>"+
        "<button type='button' class='ManagerButton' id='Button5' onClick='updata({0})'><img src='../images/submit.gif'/>保存</button>"+
    "</td><td>"+
        "<button type='button' class='ManagerButton' id='Button1' onClick='deldata({0})'><img src='../images/state1.gif'/>删除</button></td></tr>";

       function upcount()
       {
            var listobj=jQuery("input[d='hi']");
            var len=jQuery(listobj).size();
            jQuery("#datacount").html(len);
            
       }
       upcount();
       
        function deldata(data_id)
        {
            Forum.Web.Admin.Recommend.AddData.DelData(data_id,function(res){
                jQuery("#tr_"+data_id).remove();
                upcount();
            });
        }
        
        //排序
        function showsor()
        {
            var listobj=jQuery("input[d='hi']");
            var len=jQuery(listobj).size();
            
            if(len>0){
                jQuery(listobj).each(function(i) {
                    jQuery(this).val((i+1));
                });
                
                updata2();//批量更新
            }
        }
        
        function updata2()
        {
            var listobj=jQuery("input[d='hi']");
            var len=jQuery(listobj).size();
            
            if(len>0){
               jQuery(listobj).each(function(i){
                      var priid=jQuery(this).attr("v");
                      updata(priid);
                });
            }
        }
        
        function updata(data_id)
        {
              var id_=data_id;
              var type_=jQuery("#fld_sort_"+data_id).attr("t");
              var fuid_=pid;
              var bodyid_=jQuery("#fld_sort_"+data_id).attr("bodyid");
              var name_=jQuery("#fld_name_"+data_id).val();
              var sort_=jQuery("#fld_sort_"+data_id).val();
              var tu_=jQuery("#fld_tu_"+data_id).val();
              var sm_=jQuery("#fld_sm_"+data_id).val();
              var links_=jQuery("#fld_link_"+data_id).val();
              var color_=jQuery("#fld_color_"+data_id).val();
              var bold_=jQuery("#fld_Bold_"+data_id).attr("checked");

              var  r_body=jQuery("#r_body_"+data_id).val();
              var  r_spare=jQuery("#r_spare_"+data_id).val();
              var  r_rpare2=jQuery("#r_rpare2_"+data_id).val();
              
              Forum.Web.Admin.Recommend.AddData.Add(id_,type_, fuid_,bodyid_, name_, sm_, sort_,  tu_, links_,  color_, bold_,r_body,r_spare,r_rpare2,function(res){});
        }
        function onsub__()
        {
            var listobj=jQuery("input[d='hi']");
            var len=jQuery(listobj).size();
            
            
            
              var id_=0;
              var type_=1;
              var fuid_=pid;
              var bodyid_=0;
              var name_=jQuery("#f_name").val();
              var sort_=(len+1);
              var tu_=jQuery("#f_linkurl").val();
              var sm_=jQuery("#TextBox1").val();
              var links_=jQuery("#f_shuoming").val();
              var color_=jQuery("#TextBox2").val();
              var bold_=jQuery("#Checkbox1").attr("checked");
              
              var ctxt=bold_?" checked ":"";
              var  r_body=jQuery("#TextBox3").val();
              var  r_spare=jQuery("#TextBox4").val();
              var  r_rpare2=jQuery("#TextBox5").val();
              
              Forum.Web.Admin.Recommend.AddData.Add(id_,type_, fuid_,bodyid_, name_, sm_, sort_,  tu_, links_,  color_, bold_,r_body,r_spare,r_rpare2,function(res){
                   if(res && res.value!=0)
                   {
                        id_=res.value;
                        jQuery("#tj_list").append(template.format(id_, type_, bodyid_, sort_,name_,sm_,tu_,links_,color_,ctxt,r_body,r_spare,r_rpare2));
                        BOX_remove('neworedit');
                        upcount();
                   }
              });
        }
        
        function tjsj(myid)
        {
            if(!getIn(myid))
            {
                var listobj=jQuery("input[d='hi']");
                var len=jQuery(listobj).size();
                //alert(len);
            
                Forum.Web.Admin.Recommend.AddData.GetModel( myid, pid, (len+1),function(res){
                    if(res && res.value!=null)
                    {
                        var model=res.value;
                        jQuery("#tj_list").append(template.format(model.RdItems_ID, model.RdItems_Type, model.RdItems_BodyID, (len+1),model.RdItems_Name,model.RdItems_Description,model.RdItems_Tu,model.RdItems_LinkURL,model.RdItems_Color,""));
                        
                        model=null;
                        delete model;
                        upcount();
                    }
                });
            }
        }
        
        //true表示列表里不存在,false表示列表里已经存在
        function getIn(data_id)
        {
            var listobj=jQuery("input[bodyid='"+data_id+"']");
            var len=jQuery(listobj).size();
            var rtf=false;
            
            if(len>0){
                rtf=true;
            }
            return rtf;
        }



        $(function() {
        $("#tj_list").sortable({ stop: function(event, ui) { showsor(); } });
            //$("#tj_list").disableSelection();
        });
    </script>

    </form>
</body>
</html>
